package cn.sh.ideal.web.login.menu.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.sh.ideal.web.login.menu.service.MenuService;
import cn.sh.ideal.web.login.menu.vo.ValidateLoginVo;

/**
 * 菜单数据取得Controller
 *
 */
@Controller
public class MenuController {

	@Autowired
	private MenuService menuService;

	@RequestMapping(value = "/MenuIndex")
	@ResponseBody
	public Object getMenuIdex() {
		Subject currentUser = SecurityUtils.getSubject();
        ValidateLoginVo vo = (ValidateLoginVo) currentUser.getPrincipal();
//        MenuEntity parameter = new MenuEntity();
//        parameter.setLoginUser(vo.getUserName());
        //过滤掉多余的“，”
        String menuIds=vo.getMenuIds();
		List<String> emp = new ArrayList<>();
		String[] sids = menuIds.split(",");
		for (int i = 0; i < sids.length; i++) {
			if (sids[i] != null || sids[i] != "") {
				emp.add(sids[i]);
			}
		}
       // parameter.setLoginMenuIds(emp);
        Object getMenuData = menuService.getMenuData(emp);
        return getMenuData;
	}
}
